home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
GNUUCP_2
/
SOURCE
/
UUMISC.C
< prev
next >
Wrap
Text File
|
1990-05-23
|
8KB
|
315 lines
/*
* @(#)uumisc.c 1.6 87/09/29 Copyright 1987 Free Software Foundation, Inc.
*
* Copying and use of this program are controlled by the terms of the
* GNU Emacs General Public License.
*
* uumisc.c
*
* Miscellaneous uucp variables and routines which are used by several
* uucp main programs.
*/
#include "includes.h" /* System include files, system dependent */
#include "uucp.h" /* Uucp definitions and parameters */
char Myname[MAX_HOST]; /* Our uucp hostname, set from usenet.ctl */
char Mynamealias[MAX_HOST]; /* Our uucp hostname, set from usenet.ctl */
char Forwarder[MAX_HOST];
char host_name[MAX_HOST] = "gnuucp"; /* Other guy's host name */
char *uuControl; /* Control file name */
char who[NAMESIZE] = "-"; /* Who sent us a file */
char *Spool; /* Spool directory root name */
char *Alias; /* Directory where aliases are kept */
char *Sysfile; /* L.sys file */
char *Userfile; /* USERFILE */
char *Pubdir; /* Public Directory */
char *Logfile; /* Logging file */
char *MLogfile; /* Logging file for mail */
char *Username; /* Username for single user machine */
char *Timezone; /* Timezone string ("EDT", "PST"....) */
char *UUCPlogname; /* Login name for UUCP */
char *UUCPpasswd; /* Password for UUCP */
char *Mail; /* Directory where mail is delivered */
long ByteTimeout; /* Lenght of time xgetc waits for a char (in secs) */
long ConnectWait; /* Max time we wait after dialing */
int debug = -1; /* -1 indicates ctl file should set it */
int ourpid = 0; /* Our process ID */
int logfd; /* file desc of uucp logfile */
struct port *ports, *porttail; /* Chain of serial port definitions */
#ifdef VMS
void *malloc();
#else
#ifndef MAC
char *malloc();
#endif
#endif
char *gimmestring(); /* Forward declaration */
/*
* Read the control file and grab a few parameters.
*/
read_params(ctl)
char *ctl;
{
FILE *fd;
char buf[MAX_CTLLINE];
register struct port *newport;
register char *cmd;
register char *p;
if (ctl) {
/* Remove any possible setuid if user spec'd a control file */
/* FIXME: this is system dependent....sigh
setuid(getuid()); */
} else {
/* Use the system default control file */
ctl = sysdep_control;
}
uuControl = ctl;
if (! (fd = fopen(ctl, "r"))) {
printf("Can't find configuration file %s\n", ctl);
return FAIL;
}
/* find path to inbound news */
Spool = "";
Alias = "";
Mail = "";
Sysfile = "";
Username = "";
Userfile = "";
Pubdir = "";
Logfile = "";
MLogfile = "";
UUCPlogname = "";
UUCPpasswd = "";
Timezone = "";
strcpy(Myname, "");
strcpy(Mynamealias, "");
strcpy(Forwarder, "");
ByteTimeout = BYTE_TIMEOUT;
ConnectWait = CONNECT_WAIT;
while ((long)NULL != (long)fgets(buf, sizeof buf, fd)) {
cmd = strtok(buf, CTL_DELIM);
if (!cmd) continue; /* Skip blank lines */
for (p = cmd; *p; p++)
if (isupper(*p)) *p = tolower(*p);
/* Now figure out which one it is */
if (strcmp(cmd, "alias") == 0) {
Alias = gimmestring();
} else if (strcmp(cmd, "spool") == 0) {
Spool = gimmestring();
} else if (strcmp(cmd, "sysfile") == 0) {
Sysfile = gimmestring();
} else if (strcmp(cmd, "username") == 0) {
Username = gimmestring();
} else if (strcmp(cmd, "uucplogname") == 0) {
UUCPlogname = gimmestring();
} else if (strcmp(cmd, "uucppasswd") == 0) {
UUCPpasswd = gimmestring();
} else if (strcmp(cmd, "mail") == 0) {
Mail = gimmestring();
} else if (strcmp(cmd, "userfile") == 0) {
Userfile = gimmestring();
} else if (strcmp(cmd, "pubdir") == 0) {
Pubdir = gimmestring();
} else if (strcmp(cmd, "logfile") == 0) {
Logfile = gimmestring();
} else if (strcmp(cmd, "timezone") == 0) {
Timezone = gimmestring();
} else if (strcmp(cmd, "mlogfile") == 0) {
MLogfile = gimmestring();
} else if (strcmp(cmd, "nodename") == 0) {
strcpy(Myname, strtok((char *)NULL, CTL_DELIM) ) ;
} else if (strcmp(cmd, "nodenamealias") == 0) {
strcpy(Mynamealias, strtok((char *)NULL, CTL_DELIM) ) ;
} else if (strcmp(cmd, "forwarder") == 0) {
strcpy(Forwarder, strtok((char *)NULL, CTL_DELIM) ) ;
}
else if (strcmp(cmd, "debug") == 0) {
if (debug < 0) {
debug = atoi(strtok((char *)NULL, CTL_DELIM));
}
}
else if (strcmp(cmd, "bytetimeout") == 0) {
{
ByteTimeout = atoi(strtok((char *)NULL, CTL_DELIM));
}
}
else if (strcmp(cmd, "connectwait") == 0) {
{
ConnectWait = atoi(strtok((char *)NULL, CTL_DELIM));
}
} else if (strcmp(cmd, "port") == 0) {
newport = (struct port *)malloc(sizeof *newport);
p = strtok((char *)NULL, CTL_DELIM);
strcpy(newport->portname, p);
p = strtok((char *)NULL, CTL_DELIM);
strcpy(newport->modemname, p);
p = strtok((char *)NULL, CTL_DELIM);
strcpy(newport->devname, p);
p = strtok((char *)NULL, CTL_DELIM);
newport->baud = atol(p);
/* Add it to the end of the chain */
newport->chain = (struct port *)0;
if (ports)
porttail->chain = newport;
else
ports = newport;
porttail = newport;
}
}
fclose(fd);
return SUCCESS;
}
/* Scan out next arg as a string, return it or NULL if none there. */
char *
gimmestring()
{
register char *p, *q;
p = strtok((char *)NULL, CTL_DELIM);
if (p == NULL)
return p;
q = (char *)malloc(strlen(p)+1);
strcpy(q, p);
return q;
}
/*
* Scan out an "argv" from a blank-separated string.
*
* Result is argc, or -1 if there are too many args.
*/
int
getargs(string, argv, maxargc)
char *string;
char **argv;
int maxargc;
{
int argc = 0;
while (*string == ' ') string++;
for (; *string; ) {
argv[argc++] = string; /* Record position */
if (argc >= maxargc) return -1;
while (*string && *string != ' ') string++;
if (*string == '\0') break;
*string++ = '\0'; /* Null terminate it */
while (*string == ' ') string++;
}
argv[argc] = (char *)0; /* Null after last one */
return argc;
}
/*
* Log file writing subroutine.
*
* Makes incredibly ugly log entries that look *just like* Unix uucp's
* incredibly ugly log entries.
*
* Once we don't care about compatability, we should do this much better.
*/
logit(one, two)
char *one, *two;
{
char logbuf[(NAMESIZE*4)+SLOP+50]; /* Temp buffer for logs */
int len;
if (logfd <= 0) {
/* Open the log file if not already open */
if (Logfile == 0 || *Logfile == 0)
return; /* If none specified, no logging. */
logfd = open(Logfile, O_CREAT|O_WRONLY|O_APPEND|O_TEXT);
if (logfd < 0) {
if (DEBUG_LEVEL(0)) perror(Logfile);
exit(EXIT_ERR);
}
}
sprintf(logbuf, "%s %s (%s) %s (%s)\n",
who, host_name, time_and_pid(), one, two);
DEBUG(0, "%s", logbuf);
len = strlen(logbuf);
if (len != write(logfd, logbuf, len)) {
if (DEBUG_LEVEL(0)) {
fprintf(stderr, "Can't write to log, terminating!\n");
perror(Logfile);
}
exit(EXIT_ERR); /* Terminate if we can't log */
}
#ifdef LOGCLOSE
if (close(logfd) != 0) {
if (DEBUG_LEVEL(0)) {
fprintf(stderr, "Can't close log, terminating!\n");
perror(Logfile);
}
exit(EXIT_ERR); /* Terminate if we can't log */
}
logfd = -1;
#endif
}
mlogit(one, two)
char *one, *two;
{
char logbuf[(NAMESIZE*4)+SLOP+50]; /* Temp buffer for logs */
int len;
if (logfd <= 0) {
/* Open the log file if not already open */
if (Logfile == 0 || *Logfile == 0)
return; /* If none specified, no logging. */
logfd = open(MLogfile, O_CREAT|O_WRONLY|O_APPEND|O_TEXT);
if (logfd < 0) {
if (DEBUG_LEVEL(0)) perror(MLogfile);
exit(EXIT_ERR);
}
}
sprintf(logbuf, "%s %s (%s) %s (%s)\n",
who, host_name, time_and_pid(), one, two);
DEBUG(0, "%s", logbuf);
len = strlen(logbuf);
if (len != write(logfd, logbuf, len)) {
if (DEBUG_LEVEL(0)) {
fprintf(stderr, "Can't write to log, terminating!\n");
perror(MLogfile);
}
exit(EXIT_ERR); /* Terminate if we can't log */
}
#ifdef LOGCLOSE
if (close(logfd) != 0) {
if (DEBUG_LEVEL(0)) {
fprintf(stderr, "Can't close log, terminating!\n");
perror(MLogfile);
}
exit(EXIT_ERR); /* Terminate if we can't log */
}
logfd = -1;
#endif
}
void
cuserid(str)
char *str;
{
strcpy(str, Username);
}